﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NDF.DataAccess.Common;
using System.Data;
using System.Reflection;
using IBM.Data.DB2;

namespace NDF.Test.DataAccess
{
    [TestClass]
    public class DB2DatabaseTest
    {
        [TestMethod]
        public void TestMethod1()
        {
            Database database = DatabaseFactories.CreateDatabase("DB2ContextTest");
            DataTable table = database.ExecuteDataTable("SELECT * FROM sysibm.SYSCOLUMNS");
            foreach (DataRow row in table.Rows)
            {
                Console.WriteLine(row["NAME"]);
            }
        }

        [TestMethod]
        public void TestMethod2()
        {
            Database database = DatabaseFactories.CreateDatabase("DB2ContextTest");
            DataTable table = database.ExecuteDataTable("SELECT * FROM sysibm.SYSCOLUMNS WHERE NAME LIKE '%' || @name || '%'", "DIV");
            foreach (DataRow row in table.Rows)
            {
                Console.WriteLine(row["NAME"]);
            }
        }


        [TestMethod]
        public void TestMethod3()
        {
            string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DB2ContextTest"].ConnectionString;
            DataTable table = new DataTable();
            using (DB2Connection conn = new DB2Connection(connectionString))
            {
                DB2Command command = conn.CreateCommand();
                command.CommandText = "SELECT * FROM sysibm.SYSCOLUMNS";
                DB2DataAdapter adapter = new DB2DataAdapter(command);
                adapter.Fill(table);
            }
            foreach (DataRow row in table.Rows)
            {
                Console.WriteLine(row[0]);
            }
        }

        [TestMethod]
        public void TestMethod4()
        {
            var assembly = Assembly.GetAssembly(typeof(DB2Connection));
            var assemblies = assembly.GetReferencedAssemblies();
            foreach (var assem in assemblies)
            {
                Console.WriteLine(assem.FullName);
            }
        }
    }
}
